﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;

namespace AutoLoL.Entities
{
    public class MasteryValue : MasteryBase, INotifyPropertyChanged
    {
        public MasteryValue(MasteryBase mastery)
        {
            this.Name = mastery.Name;
            this.IconBitmapImage = mastery.IconBitmapImage;
            this.MasteryId = mastery.MasteryId;
            this.MaximumRank = mastery.MaximumRank;
            this.Column = mastery.Column;
            this.Row = mastery.Row;
            this.PointsToActivate = mastery.PointsToActivate;
            this.Descriptions = mastery.Descriptions;
            this.IconBitmapImageDisabled = mastery.IconBitmapImageDisabled;
            this.Prerequisite = mastery.Prerequisite;
        }

        public bool CanIncreaseValue { get; set; }

        public bool CanDecreaseValue { get; set; }

        public MasteryTree MasteryTree { get; set; }

        public BitmapSource Image
        {
            get
            {
                return (CanIncreaseValue || CurrentRank > 0 ? this.IconBitmapImage : this.IconBitmapImageDisabled);
            }
        }

        private int _currentRank = 0;
        public int CurrentRank
        {
            get { return _currentRank; }
            set
            {
                _currentRank = value;
                OnPropertyChanged("CurrentRank");
            }
        }

        public string CurrentLevelDescription
        {
            get
            {
                if (CurrentRank == 0 || string.IsNullOrEmpty(Descriptions[CurrentRank - 1]))
                {
                    return null;
                }

                return Descriptions[CurrentRank - 1];
            }
        }

        public string NextLevelDescription
        {
            get
            {
                if (CurrentRank == 5 || Descriptions.Length < CurrentRank || CurrentRank == MaximumRank)
                {
                    return null;
                }

                return Descriptions[CurrentRank];
            }
        }

        public void UpdateBindings()
        {
            OnPropertyChanged("Image");
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
